﻿using ERPEF;
using ERPEF.Model;
using ERPIService;
using Microsoft.EntityFrameworkCore;
using S4Project;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERPService
{
    public class bs_vendorService : bs_vendorIService
    {

        private readonly MyDbContext myDbContext;

        public bs_vendorService(MyDbContext myDbContext)
        {
            this.myDbContext = myDbContext;
        }

        public async Task<int> Add(bs_vendor bsVendor)
        {
           myDbContext.bs_Vendor.Add(bsVendor);
           return await myDbContext.SaveChangesAsync();
        }

        public async Task<int> Delete(int vendor_id)
        {
            var del = myDbContext.bs_Vendor.Find(vendor_id);
            if (del != null) 
            {
               del.IsDeleted = true;
               await myDbContext.SaveChangesAsync();
                return 1;
            }
            return 0;
        }

        public async Task<List<bs_vendor>> Query()
        {
            return await myDbContext.bs_Vendor.Where(v => v.IsDeleted == false).ToListAsync();
        }

        public async Task<int> Uadate(bs_vendor bs_Vendor)
        {
            myDbContext.bs_Vendor.Update(bs_Vendor);
            return await myDbContext.SaveChangesAsync();
        }
    }
}
